﻿#region Apache Notice
/*****************************************************************************
 * $Revision: 374175 $
 * $LastChangedDate: 2006-02-19 12:37:22 +0100 (Sun, 19 Feb 2006) $
 * $LastChangedBy: gbayon $
 * 
 * iBATIS.NET Data Mapper
 * Copyright (C) 2006/2005 - The Apache Software Foundation
 *  
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 ********************************************************************************/
#endregion

#region using
using System;
using System.Collections;
#if NET_2_0
using System.Collections.Generic;
#endif
using System.Collections.Specialized;
using System.Data;

using IBatisNet.Common;
using IBatisNet.Common.Utilities.Objects;
using IBatisNet.Common.Utilities.Objects.Members;
using IBatisNet.DataMapper.Configuration.Cache;
using IBatisNet.DataMapper.Configuration.ParameterMapping;
//// using IBatisNet.DataMapper.Configuration.ResultMapping;
using IBatisNet.DataMapper.DataExchange;
using IBatisNet.DataMapper.Exceptions;
using IBatisNet.DataMapper.MappedStatements;
using IBatisNet.DataMapper.SessionStore;
using IBatisNet.DataMapper.TypeHandlers;
using IBatisNet.Common.Utilities;
#endregion

namespace IBatisNet.DataMapper
{
    /// <summary>
    /// Contract for an <see cref="ISqlMapper"/>
    /// </summary>
    public interface ISqlMapper
    {

        /// <summary>
        /// Name used to identify the the <see cref="SqlMapper"/>
        /// </summary>
        string Id { get; }
        
         /// <summary>
        /// Allow to set a custom session store like the <see cref="HybridWebThreadSessionStore"/>
        /// </summary>
        /// <remarks>Set it after the configuration and before use of the <see cref="SqlMapper"/></remarks>
        /// <example>
        /// sqlMapper.SessionStore = new HybridWebThreadSessionStore( sqlMapper.Id );
        /// </example>
        ISessionStore SessionStore { set; }
        
        /// <summary>
        /// Gets a value indicating whether this instance is session started.
        /// </summary>
        /// <value>
        /// 	<c>true</c> if this instance is session started; otherwise, <c>false</c>.
        /// </value>
        bool IsSessionStarted { get; }
        
        /// <summary>
        ///  Returns the DalSession instance 
        ///  currently being used by the SqlMap.
        /// </summary>
        ISqlMapSession LocalSession { get; }

        /// <summary>
        /// Gets the DB helper parameter cache.
        /// </summary>
        /// <value>The DB helper parameter cache.</value>
        DBHelperParameterCache DBHelperParameterCache { get; }

       
        
        /// <summary>
        /// A flag that determines whether cache models were enabled 
        /// when this SqlMap was built.
        /// </summary>
        bool IsCacheModelsEnabled { get;set; }
        
        /// <summary>
		/// Factory for DataExchange objects
		/// </summary>
        DataExchangeFactory DataExchangeFactory { get; }
        
        /// <summary>
		/// The TypeHandlerFactory
		/// </summary>
        TypeHandlerFactory TypeHandlerFactory { get; }
		
        /// <summary>
        /// The meta factory for object factory
        /// </summary>
        IObjectFactory ObjectFactory { get; }
        
        /// <summary>
        /// The factory which build <see cref="IAccessor"/>
        /// </summary>
        AccessorFactory AccessorFactory { get; }
        
        /// <summary>
		/// Get a ParameterMap by name
		/// </summary>
		/// <param name="name">The name of the ParameterMap</param>
		/// <returns>The ParameterMap</returns>
        ParameterMap GetParameterMap(string name); 
        
        /// <summary>
		/// Adds a (named) ParameterMap.
		/// </summary>
		/// <param name="parameterMap">the ParameterMap to add</param>
        void AddParameterMap(ParameterMap parameterMap);
        
  //      /// <summary>
		///// Gets a ResultMap by name
		///// </summary>
		///// <param name="name">The name of the result map</param>
		///// <returns>The ResultMap</returns>
  //      IResultMap GetResultMap(string name);
        
  //      /// <summary>
		///// Adds a (named) ResultMap
		///// </summary>
		///// <param name="resultMap">The ResultMap to add</param>
  //      void AddResultMap(IResultMap resultMap);
        
        /// <summary>
		/// The ParameterMap collection
		/// </summary>
        HybridDictionary ParameterMaps { get; }
        
  //      /// <summary>
		///// The ResultMap collection
		///// </summary>
  //      HybridDictionary ResultMaps { get; }
        
        /// <summary>
		/// The MappedStatements collection
		/// </summary>
        HybridDictionary MappedStatements { get; }
        
        /// <summary>
		/// Gets a cache by name
		/// </summary>
		/// <param name="name">The name of the cache to get</param>
		/// <returns>The cache object</returns>
        CacheModel GetCache(string name);
        
        /// <summary>
		/// Adds a (named) cache.
		/// </summary>
		/// <param name="cache">The cache to add</param>
        void AddCache(CacheModel cache);
        
        /// <summary>
		/// Adds a (named) MappedStatement.
		/// </summary>
		/// <param name="key"> The key name</param>
		/// <param name="mappedStatement">The statement to add</param>
        void AddMappedStatement(string key, IMappedStatement mappedStatement);
        
          
        /////// <summary>
        /////// Gets or sets the data source.
        /////// </summary>
        /////// <value>The data source.</value>
        ////IDataSource DataSource { get; set; }
         

        /// <summary>
        /// Flushes all cached objects that belong to this SqlMap
        /// </summary>
        void FlushCaches();

        /// <summary>
        /// Gets the data cache stats.
        /// </summary>
        /// <returns></returns>
        string GetDataCacheStats();

        /// <summary>
		/// Gets a MappedStatement by name
		/// </summary>
		/// <param name="id"> The id of the statement</param>
		/// <returns> The MappedStatement</returns>
        IMappedStatement GetMappedStatement(string id);
         
         
    }
}
